<!DOCTYPE html>
<html lang="en">
<head>
    
    <meta charset="utf-8">
    <title>libs/zlib.js - Documentation</title>
    
    
    <script src="scripts/prettify/prettify.js"></script>
    <script src="scripts/prettify/lang-css.js"></script>
    <!--[if lt IE 9]>
      <script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
    <![endif]-->
    <link type="text/css" rel="stylesheet" href="styles/prettify.css">
    <link type="text/css" rel="stylesheet" href="styles/jsdoc.css">
    <script src="scripts/nav.js" defer></script>
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>

<input type="checkbox" id="nav-trigger" class="nav-trigger" />
<label for="nav-trigger" class="navicon-button x">
  <div class="navicon"></div>
</label>

<label for="nav-trigger" class="overlay"></label>

<nav >
    
    <h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="GState.html">GState</a></li><li><a href="jsPDF.html">jsPDF</a><ul class='methods'><li data-type='method'><a href="jsPDF.html#addFont">addFont</a></li><li data-type='method'><a href="jsPDF.html#addGState">addGState</a></li><li data-type='method'><a href="jsPDF.html#addPage">addPage</a></li><li data-type='method'><a href="jsPDF.html#addPattern">addPattern</a></li><li data-type='method'><a href="jsPDF.html#beginFormObject">beginFormObject</a></li><li data-type='method'><a href="jsPDF.html#circle">circle</a></li><li data-type='method'><a href="jsPDF.html#clip">clip</a></li><li data-type='method'><a href="jsPDF.html#clipEvenOdd">clipEvenOdd</a></li><li data-type='method'><a href="jsPDF.html#close">close</a></li><li data-type='method'><a href="jsPDF.html#comment">comment</a></li><li data-type='method'><a href="jsPDF.html#curveTo">curveTo</a></li><li data-type='method'><a href="jsPDF.html#deletePage">deletePage</a></li><li data-type='method'><a href="jsPDF.html#discardPath">discardPath</a></li><li data-type='method'><a href="jsPDF.html#doFormObject">doFormObject</a></li><li data-type='method'><a href="jsPDF.html#ellipse">ellipse</a></li><li data-type='method'><a href="jsPDF.html#endFormObject">endFormObject</a></li><li data-type='method'><a href="jsPDF.html#fill">fill</a></li><li data-type='method'><a href="jsPDF.html#fillEvenOdd">fillEvenOdd</a></li><li data-type='method'><a href="jsPDF.html#fillStroke">fillStroke</a></li><li data-type='method'><a href="jsPDF.html#fillStrokeEvenOdd">fillStrokeEvenOdd</a></li><li data-type='method'><a href="jsPDF.html#getCharSpace">getCharSpace</a></li><li data-type='method'><a href="jsPDF.html#getCreationDate">getCreationDate</a></li><li data-type='method'><a href="jsPDF.html#getDrawColor">getDrawColor</a></li><li data-type='method'><a href="jsPDF.html#getFileId">getFileId</a></li><li data-type='method'><a href="jsPDF.html#getFillColor">getFillColor</a></li><li data-type='method'><a href="jsPDF.html#getFont">getFont</a></li><li data-type='method'><a href="jsPDF.html#getFontList">getFontList</a></li><li data-type='method'><a href="jsPDF.html#getFontSize">getFontSize</a></li><li data-type='method'><a href="jsPDF.html#getFormObject">getFormObject</a></li><li data-type='method'><a href="jsPDF.html#getLineHeightFactor">getLineHeightFactor</a></li><li data-type='method'><a href="jsPDF.html#getR2L">getR2L</a></li><li data-type='method'><a href="jsPDF.html#getTextColor">getTextColor</a></li><li data-type='method'><a href="jsPDF.html#insertPage">insertPage</a></li><li data-type='method'><a href="jsPDF.html#line">line</a></li><li data-type='method'><a href="jsPDF.html#lines">lines</a></li><li data-type='method'><a href="jsPDF.html#lineTo">lineTo</a></li><li data-type='method'><a href="jsPDF.html#movePage">movePage</a></li><li data-type='method'><a href="jsPDF.html#moveTo">moveTo</a></li><li data-type='method'><a href="jsPDF.html#output">output</a></li><li data-type='method'><a href="jsPDF.html#path">path</a></li><li data-type='method'><a href="jsPDF.html#rect">rect</a></li><li data-type='method'><a href="jsPDF.html#restoreGraphicsState">restoreGraphicsState</a></li><li data-type='method'><a href="jsPDF.html#roundedRect">roundedRect</a></li><li data-type='method'><a href="jsPDF.html#save">save</a></li><li data-type='method'><a href="jsPDF.html#saveGraphicsState">saveGraphicsState</a></li><li data-type='method'><a href="jsPDF.html#setCharSpace">setCharSpace</a></li><li data-type='method'><a href="jsPDF.html#setCreationDate">setCreationDate</a></li><li data-type='method'><a href="jsPDF.html#setCurrentTransformationMatrix">setCurrentTransformationMatrix</a></li><li data-type='method'><a href="jsPDF.html#setDisplayMode">setDisplayMode</a></li><li data-type='method'><a href="jsPDF.html#setDocumentProperties">setDocumentProperties</a></li><li data-type='method'><a href="jsPDF.html#setDrawColor">setDrawColor</a></li><li data-type='method'><a href="jsPDF.html#setFileId">setFileId</a></li><li data-type='method'><a href="jsPDF.html#setFillColor">setFillColor</a></li><li data-type='method'><a href="jsPDF.html#setFont">setFont</a></li><li data-type='method'><a href="jsPDF.html#setFontSize">setFontSize</a></li><li data-type='method'><a href="jsPDF.html#setGState">setGState</a></li><li data-type='method'><a href="jsPDF.html#setLineCap">setLineCap</a></li><li data-type='method'><a href="jsPDF.html#setLineDashPattern">setLineDashPattern</a></li><li data-type='method'><a href="jsPDF.html#setLineHeightFactor">setLineHeightFactor</a></li><li data-type='method'><a href="jsPDF.html#setLineJoin">setLineJoin</a></li><li data-type='method'><a href="jsPDF.html#setLineMiterLimit">setLineMiterLimit</a></li><li data-type='method'><a href="jsPDF.html#setLineWidth">setLineWidth</a></li><li data-type='method'><a href="jsPDF.html#setPage">setPage</a></li><li data-type='method'><a href="jsPDF.html#setPrecision">setPrecision</a></li><li data-type='method'><a href="jsPDF.html#setR2L">setR2L</a></li><li data-type='method'><a href="jsPDF.html#setTextColor">setTextColor</a></li><li data-type='method'><a href="jsPDF.html#stroke">stroke</a></li><li data-type='method'><a href="jsPDF.html#text">text</a></li><li data-type='method'><a href="jsPDF.html#triangle">triangle</a></li><li data-type='method'><a href="jsPDF.html#~addGState">addGState</a></li><li data-type='method'><a href="jsPDF.html#~addPattern">addPattern</a></li><li data-type='method'><a href="jsPDF.html#~hasHotfix">hasHotfix</a></li><li data-type='method'><a href="jsPDF.html#~Point">Point</a></li><li data-type='method'><a href="jsPDF.html#~Rectangle">Rectangle</a></li><li data-type='method'><a href="jsPDF.html#~RenderTarget">RenderTarget</a></li></ul></li><li><a href="jsPDF-API.GState.html">GState</a></li><li><a href="jsPDF-API.ShadingPattern.html">ShadingPattern</a></li><li><a href="jsPDF-API.TilingPattern.html">TilingPattern</a></li><li><a href="Matrix.html">Matrix</a><ul class='methods'><li data-type='method'><a href="Matrix.html#applyToPoint">applyToPoint</a></li><li data-type='method'><a href="Matrix.html#applyToRectangle">applyToRectangle</a></li><li data-type='method'><a href="Matrix.html#clone">clone</a></li><li data-type='method'><a href="Matrix.html#decompose">decompose</a></li><li data-type='method'><a href="Matrix.html#inversed">inversed</a></li><li data-type='method'><a href="Matrix.html#join">join</a></li><li data-type='method'><a href="Matrix.html#multiply">multiply</a></li><li data-type='method'><a href="Matrix.html#toString">toString</a></li></ul></li><li><a href="module-AcroForm-AcroFormButton.html">AcroFormButton</a></li><li><a href="module-AcroForm-AcroFormCheckBox.html">AcroFormCheckBox</a></li><li><a href="module-AcroForm-AcroFormChoiceField.html">AcroFormChoiceField</a></li><li><a href="module-AcroForm-AcroFormComboBox.html">AcroFormComboBox</a><ul class='methods'><li data-type='method'><a href="module-AcroForm-AcroFormComboBox.html#addOption">addOption</a></li><li data-type='method'><a href="module-AcroForm-AcroFormComboBox.html#getOptions">getOptions</a></li><li data-type='method'><a href="module-AcroForm-AcroFormComboBox.html#removeOption">removeOption</a></li><li data-type='method'><a href="module-AcroForm-AcroFormComboBox.html#setOptions">setOptions</a></li></ul></li><li><a href="module-AcroForm-AcroFormEditBox.html">AcroFormEditBox</a><ul class='methods'><li data-type='method'><a href="module-AcroForm-AcroFormEditBox.html#addOption">addOption</a></li><li data-type='method'><a href="module-AcroForm-AcroFormEditBox.html#getOptions">getOptions</a></li><li data-type='method'><a href="module-AcroForm-AcroFormEditBox.html#removeOption">removeOption</a></li><li data-type='method'><a href="module-AcroForm-AcroFormEditBox.html#setOptions">setOptions</a></li></ul></li><li><a href="module-AcroForm-AcroFormField.html">AcroFormField</a></li><li><a href="module-AcroForm-AcroFormListBox.html">AcroFormListBox</a><ul class='methods'><li data-type='method'><a href="module-AcroForm-AcroFormListBox.html#addOption">addOption</a></li><li data-type='method'><a href="module-AcroForm-AcroFormListBox.html#getOptions">getOptions</a></li><li data-type='method'><a href="module-AcroForm-AcroFormListBox.html#removeOption">removeOption</a></li><li data-type='method'><a href="module-AcroForm-AcroFormListBox.html#setOptions">setOptions</a></li></ul></li><li><a href="module-AcroForm-AcroFormPasswordField.html">AcroFormPasswordField</a></li><li><a href="module-AcroForm-AcroFormPDFObject.html">AcroFormPDFObject</a></li><li><a href="module-AcroForm-AcroFormPushButton.html">AcroFormPushButton</a></li><li><a href="module-AcroForm-AcroFormRadioButton.html">AcroFormRadioButton</a></li><li><a href="module-AcroForm-AcroFormTextField.html">AcroFormTextField</a></li><li><a href="module-canvas-Canvas.html">Canvas</a></li></ul><h3>Modules</h3><ul><li><a href="module-AcroForm.html">AcroForm</a><ul class='methods'><li data-type='method'><a href="module-AcroForm.html#addField">addField</a></li><li data-type='method'><a href="module-AcroForm.html#~AcroFormDictionaryCallback">AcroFormDictionaryCallback</a></li><li data-type='method'><a href="module-AcroForm.html#~calculateFontSpace">calculateFontSpace</a></li><li data-type='method'><a href="module-AcroForm.html#~createAnnotationReference">createAnnotationReference</a></li><li data-type='method'><a href="module-AcroForm.html#~createFieldCallback">createFieldCallback</a></li></ul></li><li><a href="module-addImage.html">addImage</a><ul class='methods'><li data-type='method'><a href="module-addImage.html#~addImage">addImage</a></li><li data-type='method'><a href="module-addImage.html#~arrayBufferToBinaryString">arrayBufferToBinaryString</a></li><li data-type='method'><a href="module-addImage.html#~binaryStringToUint8Array">binaryStringToUint8Array</a></li><li data-type='method'><a href="module-addImage.html#~convertBase64ToBinaryString">convertBase64ToBinaryString</a></li><li data-type='method'><a href="module-addImage.html#~extractImageFromDataUrl">extractImageFromDataUrl</a></li><li data-type='method'><a href="module-addImage.html#~getImageFileTypeByImageData">getImageFileTypeByImageData</a></li><li data-type='method'><a href="module-addImage.html#~getImageProperties">getImageProperties</a></li><li data-type='method'><a href="module-addImage.html#~isArrayBuffer">isArrayBuffer</a></li><li data-type='method'><a href="module-addImage.html#~isArrayBufferView">isArrayBufferView</a></li><li data-type='method'><a href="module-addImage.html#~sHashCode">sHashCode</a></li><li data-type='method'><a href="module-addImage.html#~supportsArrayBuffer">supportsArrayBuffer</a></li><li data-type='method'><a href="module-addImage.html#~validateStringAsBase64">validateStringAsBase64</a></li></ul></li><li><a href="module-annotations.html">annotations</a><ul class='methods'><li data-type='method'><a href="module-annotations.html#~createAnnotation">createAnnotation</a></li><li data-type='method'><a href="module-annotations.html#~getTextWidth">getTextWidth</a></li><li data-type='method'><a href="module-annotations.html#~link">link</a></li><li data-type='method'><a href="module-annotations.html#~textWithLink">textWithLink</a></li></ul></li><li><a href="module-arabic.html">arabic</a><ul class='methods'><li data-type='method'><a href="module-arabic.html#~processArabic">processArabic</a></li></ul></li><li><a href="module-autoprint.html">autoprint</a><ul class='methods'><li data-type='method'><a href="module-autoprint.html#~autoPrint">autoPrint</a></li></ul></li><li><a href="module-bmp_support.html">bmp_support</a></li><li><a href="module-canvas.html">canvas</a><ul class='methods'><li data-type='method'><a href="module-canvas.html#~getContext">getContext</a></li><li data-type='method'><a href="module-canvas.html#~toDataURL">toDataURL</a></li></ul></li><li><a href="module-cell.html">cell</a><ul class='methods'><li data-type='method'><a href="module-cell.html#~cell">cell</a></li><li data-type='method'><a href="module-cell.html#~cellAddPage">cellAddPage</a></li><li data-type='method'><a href="module-cell.html#~getTextDimensions">getTextDimensions</a></li><li data-type='method'><a href="module-cell.html#~printHeaderRow">printHeaderRow</a></li><li data-type='method'><a href="module-cell.html#~setHeaderFunction">setHeaderFunction</a></li><li data-type='method'><a href="module-cell.html#~setTableHeaderRow">setTableHeaderRow</a></li><li data-type='method'><a href="module-cell.html#~table">table</a></li></ul></li><li><a href="module-context2d.html">context2d</a><ul class='methods'><li data-type='method'><a href="module-context2d.html#~arc">arc</a></li><li data-type='method'><a href="module-context2d.html#~arcTo">arcTo</a></li><li data-type='method'><a href="module-context2d.html#~beginPath">beginPath</a></li><li data-type='method'><a href="module-context2d.html#~bezierCurveTo">bezierCurveTo</a></li><li data-type='method'><a href="module-context2d.html#~clearRect">clearRect</a></li><li data-type='method'><a href="module-context2d.html#~clip">clip</a></li><li data-type='method'><a href="module-context2d.html#~closePath">closePath</a></li><li data-type='method'><a href="module-context2d.html#~createArc">createArc</a></li><li data-type='method'><a href="module-context2d.html#~fillRect">fillRect</a></li><li data-type='method'><a href="module-context2d.html#~fillText">fillText</a></li><li data-type='method'><a href="module-context2d.html#~lineTo">lineTo</a></li><li data-type='method'><a href="module-context2d.html#~measureText">measureText</a></li><li data-type='method'><a href="module-context2d.html#~moveTo">moveTo</a></li><li data-type='method'><a href="module-context2d.html#~quadraticCurveTo">quadraticCurveTo</a></li><li data-type='method'><a href="module-context2d.html#~rect">rect</a></li><li data-type='method'><a href="module-context2d.html#~restore">restore</a></li><li data-type='method'><a href="module-context2d.html#~rotate">rotate</a></li><li data-type='method'><a href="module-context2d.html#~save">save</a></li><li data-type='method'><a href="module-context2d.html#~scale">scale</a></li><li data-type='method'><a href="module-context2d.html#~setTransform">setTransform</a></li><li data-type='method'><a href="module-context2d.html#~stroke">stroke</a></li><li data-type='method'><a href="module-context2d.html#~strokeRect">strokeRect</a></li><li data-type='method'><a href="module-context2d.html#~strokeText">strokeText</a></li><li data-type='method'><a href="module-context2d.html#~toDataURL">toDataURL</a></li><li data-type='method'><a href="module-context2d.html#~transform">transform</a></li><li data-type='method'><a href="module-context2d.html#~translate">translate</a></li></ul></li><li><a href="module-fileloading.html">fileloading</a><ul class='methods'><li data-type='method'><a href="module-fileloading.html#~loadFile">loadFile</a></li><li data-type='method'><a href="module-fileloading.html#~loadImageFile">loadImageFile</a></li></ul></li><li><a href="module-gif_support.html">gif_support</a></li><li><a href="module-html.html">html</a><ul class='methods'><li data-type='method'><a href="module-html.html#~html">html</a></li></ul></li><li><a href="module-javascript.html">javascript</a><ul class='methods'><li data-type='method'><a href="module-javascript.html#~addJS">addJS</a></li></ul></li><li><a href="module-jpeg_support.html">jpeg_support</a></li><li><a href="module-outline.html">outline</a></li><li><a href="module-png_support.html">png_support</a></li><li><a href="module-setLanguage.html">setLanguage</a><ul class='methods'><li data-type='method'><a href="module-setLanguage.html#~setLanguage">setLanguage</a></li></ul></li><li><a href="module-split_text_to_size.html">split_text_to_size</a><ul class='methods'><li data-type='method'><a href="module-split_text_to_size.html#~getCharWidthsArray">getCharWidthsArray</a></li><li data-type='method'><a href="module-split_text_to_size.html#~getStringUnitWidth">getStringUnitWidth</a></li><li data-type='method'><a href="module-split_text_to_size.html#~splitTextToSize">splitTextToSize</a></li></ul></li><li><a href="module-standard_fonts_metrics.html">standard_fonts_metrics</a></li><li><a href="module-svg.html">svg</a><ul class='methods'><li data-type='method'><a href="module-svg.html#~addSvgAsImage">addSvgAsImage</a></li></ul></li><li><a href="module-total_pages.html">total_pages</a><ul class='methods'><li data-type='method'><a href="module-total_pages.html#~putTotalPages">putTotalPages</a></li></ul></li><li><a href="module-ttfsupport.html">ttfsupport</a></li><li><a href="module-utf8.html">utf8</a></li><li><a href="module-vFS.html">vFS</a><ul class='methods'><li data-type='method'><a href="module-vFS.html#~addFileToVFS">addFileToVFS</a></li><li data-type='method'><a href="module-vFS.html#~existsFileInVFS">existsFileInVFS</a></li><li data-type='method'><a href="module-vFS.html#~getFileFromVFS">getFileFromVFS</a></li></ul></li><li><a href="module-viewerpreferences.html">viewerpreferences</a><ul class='methods'><li data-type='method'><a href="module-viewerpreferences.html#~viewerPreferences">viewerPreferences</a></li></ul></li><li><a href="module-webp_support.html">webp_support</a></li><li><a href="module-xmp_metadata.html">xmp_metadata</a><ul class='methods'><li data-type='method'><a href="module-xmp_metadata.html#~addMetadata">addMetadata</a></li></ul></li></ul><h3>Global</h3><ul><li><a href="global.html#constructor">constructor</a></li><li><a href="global.html#DecodeStream">DecodeStream</a></li><li><a href="global.html#encryptor">encryptor</a></li><li><a href="global.html#hexToBytes">hexToBytes</a></li><li><a href="global.html#lsbFirstWord">lsbFirstWord</a></li><li><a href="global.html#mapArrayBufferViews">mapArrayBufferViews</a></li><li><a href="global.html#md5cycle">md5cycle</a></li><li><a href="global.html#processOwnerPassword">processOwnerPassword</a></li><li><a href="global.html#rc4">rc4</a></li><li><a href="global.html#repeat">repeat</a></li><li><a href="global.html#RGBColor">RGBColor</a></li><li><a href="global.html#SetsoptionsforBidiconversion">Sets options for Bidi conversion</a></li><li><a href="global.html#toHexString">toHexString</a></li></ul>
</nav>

<div id="main">
    
    <h1 class="page-title">libs/zlib.js</h1>
    

    



    
    <section>
        <article>
            <pre class="prettyprint source linenums"><code>/**
 * @license
 * Extracted from pdf.js
 * https://github.com/andreasgal/pdf.js
 *
 * Copyright (c) 2011 Mozilla Foundation
 *
 * Contributors: Andreas Gal &lt;gal@mozilla.com>
 *               Chris G Jones &lt;cjones@mozilla.com>
 *               Shaon Barman &lt;shaon.barman@gmail.com>
 *               Vivien Nicolas &lt;21@vingtetun.org>
 *               Justin D'Arcangelo &lt;justindarc@gmail.com>
 *               Yury Delendik
 *
 * Permission is hereby granted, free of charge, to any person obtaining a
 * copy of this software and associated documentation files (the "Software"),
 * to deal in the Software without restriction, including without limitation
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
 * and/or sell copies of the Software, and to permit persons to whom the
 * Software is furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
 * DEALINGS IN THE SOFTWARE.
 */

var DecodeStream = (function() {
  function constructor() {
    this.pos = 0;
    this.bufferLength = 0;
    this.eof = false;
    this.buffer = null;
  }

  constructor.prototype = {
    ensureBuffer: function decodestream_ensureBuffer(requested) {
      var buffer = this.buffer;
      var current = buffer ? buffer.byteLength : 0;
      if (requested &lt; current) return buffer;
      var size = 512;
      while (size &lt; requested) size &lt;&lt;= 1;
      var buffer2 = new Uint8Array(size);
      for (var i = 0; i &lt; current; ++i) buffer2[i] = buffer[i];
      return (this.buffer = buffer2);
    },
    getByte: function decodestream_getByte() {
      var pos = this.pos;
      while (this.bufferLength &lt;= pos) {
        if (this.eof) return null;
        this.readBlock();
      }
      return this.buffer[this.pos++];
    },
    getBytes: function decodestream_getBytes(length) {
      var pos = this.pos;

      if (length) {
        this.ensureBuffer(pos + length);
        var end = pos + length;

        while (!this.eof &amp;&amp; this.bufferLength &lt; end) this.readBlock();

        var bufEnd = this.bufferLength;
        if (end > bufEnd) end = bufEnd;
      } else {
        while (!this.eof) this.readBlock();

        var end = this.bufferLength;
      }

      this.pos = end;
      return this.buffer.subarray(pos, end);
    },
    lookChar: function decodestream_lookChar() {
      var pos = this.pos;
      while (this.bufferLength &lt;= pos) {
        if (this.eof) return null;
        this.readBlock();
      }
      return String.fromCharCode(this.buffer[this.pos]);
    },
    getChar: function decodestream_getChar() {
      var pos = this.pos;
      while (this.bufferLength &lt;= pos) {
        if (this.eof) return null;
        this.readBlock();
      }
      return String.fromCharCode(this.buffer[this.pos++]);
    },
    makeSubStream: function decodestream_makeSubstream(start, length, dict) {
      var end = start + length;
      while (this.bufferLength &lt;= end &amp;&amp; !this.eof) this.readBlock();
      return new Stream(this.buffer, start, length, dict);
    },
    skip: function decodestream_skip(n) {
      if (!n) n = 1;
      this.pos += n;
    },
    reset: function decodestream_reset() {
      this.pos = 0;
    }
  };

  return constructor;
})();

var globalObject =
  (typeof self !== "undefined" &amp;&amp; self) ||
  (typeof window !== "undefined" &amp;&amp; window) ||
  (typeof global !== "undefined" &amp;&amp; global) ||
  Function('return typeof this === "object" &amp;&amp; this.content')() ||
  Function("return this")();

var FlateStream = (globalObject.FlateStream = (function() {
  if (typeof Uint32Array === "undefined") {
    return undefined;
  }
  var codeLenCodeMap = new Uint32Array([
    16,
    17,
    18,
    0,
    8,
    7,
    9,
    6,
    10,
    5,
    11,
    4,
    12,
    3,
    13,
    2,
    14,
    1,
    15
  ]);

  var lengthDecode = new Uint32Array([
    0x00003,
    0x00004,
    0x00005,
    0x00006,
    0x00007,
    0x00008,
    0x00009,
    0x0000a,
    0x1000b,
    0x1000d,
    0x1000f,
    0x10011,
    0x20013,
    0x20017,
    0x2001b,
    0x2001f,
    0x30023,
    0x3002b,
    0x30033,
    0x3003b,
    0x40043,
    0x40053,
    0x40063,
    0x40073,
    0x50083,
    0x500a3,
    0x500c3,
    0x500e3,
    0x00102,
    0x00102,
    0x00102
  ]);

  var distDecode = new Uint32Array([
    0x00001,
    0x00002,
    0x00003,
    0x00004,
    0x10005,
    0x10007,
    0x20009,
    0x2000d,
    0x30011,
    0x30019,
    0x40021,
    0x40031,
    0x50041,
    0x50061,
    0x60081,
    0x600c1,
    0x70101,
    0x70181,
    0x80201,
    0x80301,
    0x90401,
    0x90601,
    0xa0801,
    0xa0c01,
    0xb1001,
    0xb1801,
    0xc2001,
    0xc3001,
    0xd4001,
    0xd6001
  ]);

  var fixedLitCodeTab = [
    new Uint32Array([
      0x70100,
      0x80050,
      0x80010,
      0x80118,
      0x70110,
      0x80070,
      0x80030,
      0x900c0,
      0x70108,
      0x80060,
      0x80020,
      0x900a0,
      0x80000,
      0x80080,
      0x80040,
      0x900e0,
      0x70104,
      0x80058,
      0x80018,
      0x90090,
      0x70114,
      0x80078,
      0x80038,
      0x900d0,
      0x7010c,
      0x80068,
      0x80028,
      0x900b0,
      0x80008,
      0x80088,
      0x80048,
      0x900f0,
      0x70102,
      0x80054,
      0x80014,
      0x8011c,
      0x70112,
      0x80074,
      0x80034,
      0x900c8,
      0x7010a,
      0x80064,
      0x80024,
      0x900a8,
      0x80004,
      0x80084,
      0x80044,
      0x900e8,
      0x70106,
      0x8005c,
      0x8001c,
      0x90098,
      0x70116,
      0x8007c,
      0x8003c,
      0x900d8,
      0x7010e,
      0x8006c,
      0x8002c,
      0x900b8,
      0x8000c,
      0x8008c,
      0x8004c,
      0x900f8,
      0x70101,
      0x80052,
      0x80012,
      0x8011a,
      0x70111,
      0x80072,
      0x80032,
      0x900c4,
      0x70109,
      0x80062,
      0x80022,
      0x900a4,
      0x80002,
      0x80082,
      0x80042,
      0x900e4,
      0x70105,
      0x8005a,
      0x8001a,
      0x90094,
      0x70115,
      0x8007a,
      0x8003a,
      0x900d4,
      0x7010d,
      0x8006a,
      0x8002a,
      0x900b4,
      0x8000a,
      0x8008a,
      0x8004a,
      0x900f4,
      0x70103,
      0x80056,
      0x80016,
      0x8011e,
      0x70113,
      0x80076,
      0x80036,
      0x900cc,
      0x7010b,
      0x80066,
      0x80026,
      0x900ac,
      0x80006,
      0x80086,
      0x80046,
      0x900ec,
      0x70107,
      0x8005e,
      0x8001e,
      0x9009c,
      0x70117,
      0x8007e,
      0x8003e,
      0x900dc,
      0x7010f,
      0x8006e,
      0x8002e,
      0x900bc,
      0x8000e,
      0x8008e,
      0x8004e,
      0x900fc,
      0x70100,
      0x80051,
      0x80011,
      0x80119,
      0x70110,
      0x80071,
      0x80031,
      0x900c2,
      0x70108,
      0x80061,
      0x80021,
      0x900a2,
      0x80001,
      0x80081,
      0x80041,
      0x900e2,
      0x70104,
      0x80059,
      0x80019,
      0x90092,
      0x70114,
      0x80079,
      0x80039,
      0x900d2,
      0x7010c,
      0x80069,
      0x80029,
      0x900b2,
      0x80009,
      0x80089,
      0x80049,
      0x900f2,
      0x70102,
      0x80055,
      0x80015,
      0x8011d,
      0x70112,
      0x80075,
      0x80035,
      0x900ca,
      0x7010a,
      0x80065,
      0x80025,
      0x900aa,
      0x80005,
      0x80085,
      0x80045,
      0x900ea,
      0x70106,
      0x8005d,
      0x8001d,
      0x9009a,
      0x70116,
      0x8007d,
      0x8003d,
      0x900da,
      0x7010e,
      0x8006d,
      0x8002d,
      0x900ba,
      0x8000d,
      0x8008d,
      0x8004d,
      0x900fa,
      0x70101,
      0x80053,
      0x80013,
      0x8011b,
      0x70111,
      0x80073,
      0x80033,
      0x900c6,
      0x70109,
      0x80063,
      0x80023,
      0x900a6,
      0x80003,
      0x80083,
      0x80043,
      0x900e6,
      0x70105,
      0x8005b,
      0x8001b,
      0x90096,
      0x70115,
      0x8007b,
      0x8003b,
      0x900d6,
      0x7010d,
      0x8006b,
      0x8002b,
      0x900b6,
      0x8000b,
      0x8008b,
      0x8004b,
      0x900f6,
      0x70103,
      0x80057,
      0x80017,
      0x8011f,
      0x70113,
      0x80077,
      0x80037,
      0x900ce,
      0x7010b,
      0x80067,
      0x80027,
      0x900ae,
      0x80007,
      0x80087,
      0x80047,
      0x900ee,
      0x70107,
      0x8005f,
      0x8001f,
      0x9009e,
      0x70117,
      0x8007f,
      0x8003f,
      0x900de,
      0x7010f,
      0x8006f,
      0x8002f,
      0x900be,
      0x8000f,
      0x8008f,
      0x8004f,
      0x900fe,
      0x70100,
      0x80050,
      0x80010,
      0x80118,
      0x70110,
      0x80070,
      0x80030,
      0x900c1,
      0x70108,
      0x80060,
      0x80020,
      0x900a1,
      0x80000,
      0x80080,
      0x80040,
      0x900e1,
      0x70104,
      0x80058,
      0x80018,
      0x90091,
      0x70114,
      0x80078,
      0x80038,
      0x900d1,
      0x7010c,
      0x80068,
      0x80028,
      0x900b1,
      0x80008,
      0x80088,
      0x80048,
      0x900f1,
      0x70102,
      0x80054,
      0x80014,
      0x8011c,
      0x70112,
      0x80074,
      0x80034,
      0x900c9,
      0x7010a,
      0x80064,
      0x80024,
      0x900a9,
      0x80004,
      0x80084,
      0x80044,
      0x900e9,
      0x70106,
      0x8005c,
      0x8001c,
      0x90099,
      0x70116,
      0x8007c,
      0x8003c,
      0x900d9,
      0x7010e,
      0x8006c,
      0x8002c,
      0x900b9,
      0x8000c,
      0x8008c,
      0x8004c,
      0x900f9,
      0x70101,
      0x80052,
      0x80012,
      0x8011a,
      0x70111,
      0x80072,
      0x80032,
      0x900c5,
      0x70109,
      0x80062,
      0x80022,
      0x900a5,
      0x80002,
      0x80082,
      0x80042,
      0x900e5,
      0x70105,
      0x8005a,
      0x8001a,
      0x90095,
      0x70115,
      0x8007a,
      0x8003a,
      0x900d5,
      0x7010d,
      0x8006a,
      0x8002a,
      0x900b5,
      0x8000a,
      0x8008a,
      0x8004a,
      0x900f5,
      0x70103,
      0x80056,
      0x80016,
      0x8011e,
      0x70113,
      0x80076,
      0x80036,
      0x900cd,
      0x7010b,
      0x80066,
      0x80026,
      0x900ad,
      0x80006,
      0x80086,
      0x80046,
      0x900ed,
      0x70107,
      0x8005e,
      0x8001e,
      0x9009d,
      0x70117,
      0x8007e,
      0x8003e,
      0x900dd,
      0x7010f,
      0x8006e,
      0x8002e,
      0x900bd,
      0x8000e,
      0x8008e,
      0x8004e,
      0x900fd,
      0x70100,
      0x80051,
      0x80011,
      0x80119,
      0x70110,
      0x80071,
      0x80031,
      0x900c3,
      0x70108,
      0x80061,
      0x80021,
      0x900a3,
      0x80001,
      0x80081,
      0x80041,
      0x900e3,
      0x70104,
      0x80059,
      0x80019,
      0x90093,
      0x70114,
      0x80079,
      0x80039,
      0x900d3,
      0x7010c,
      0x80069,
      0x80029,
      0x900b3,
      0x80009,
      0x80089,
      0x80049,
      0x900f3,
      0x70102,
      0x80055,
      0x80015,
      0x8011d,
      0x70112,
      0x80075,
      0x80035,
      0x900cb,
      0x7010a,
      0x80065,
      0x80025,
      0x900ab,
      0x80005,
      0x80085,
      0x80045,
      0x900eb,
      0x70106,
      0x8005d,
      0x8001d,
      0x9009b,
      0x70116,
      0x8007d,
      0x8003d,
      0x900db,
      0x7010e,
      0x8006d,
      0x8002d,
      0x900bb,
      0x8000d,
      0x8008d,
      0x8004d,
      0x900fb,
      0x70101,
      0x80053,
      0x80013,
      0x8011b,
      0x70111,
      0x80073,
      0x80033,
      0x900c7,
      0x70109,
      0x80063,
      0x80023,
      0x900a7,
      0x80003,
      0x80083,
      0x80043,
      0x900e7,
      0x70105,
      0x8005b,
      0x8001b,
      0x90097,
      0x70115,
      0x8007b,
      0x8003b,
      0x900d7,
      0x7010d,
      0x8006b,
      0x8002b,
      0x900b7,
      0x8000b,
      0x8008b,
      0x8004b,
      0x900f7,
      0x70103,
      0x80057,
      0x80017,
      0x8011f,
      0x70113,
      0x80077,
      0x80037,
      0x900cf,
      0x7010b,
      0x80067,
      0x80027,
      0x900af,
      0x80007,
      0x80087,
      0x80047,
      0x900ef,
      0x70107,
      0x8005f,
      0x8001f,
      0x9009f,
      0x70117,
      0x8007f,
      0x8003f,
      0x900df,
      0x7010f,
      0x8006f,
      0x8002f,
      0x900bf,
      0x8000f,
      0x8008f,
      0x8004f,
      0x900ff
    ]),
    9
  ];

  var fixedDistCodeTab = [
    new Uint32Array([
      0x50000,
      0x50010,
      0x50008,
      0x50018,
      0x50004,
      0x50014,
      0x5000c,
      0x5001c,
      0x50002,
      0x50012,
      0x5000a,
      0x5001a,
      0x50006,
      0x50016,
      0x5000e,
      0x00000,
      0x50001,
      0x50011,
      0x50009,
      0x50019,
      0x50005,
      0x50015,
      0x5000d,
      0x5001d,
      0x50003,
      0x50013,
      0x5000b,
      0x5001b,
      0x50007,
      0x50017,
      0x5000f,
      0x00000
    ]),
    5
  ];

  function error(e) {
    throw new Error(e);
  }

  function constructor(bytes) {
    //var bytes = stream.getBytes();
    var bytesPos = 0;

    var cmf = bytes[bytesPos++];
    var flg = bytes[bytesPos++];
    if (cmf == -1 || flg == -1) error("Invalid header in flate stream");
    if ((cmf &amp; 0x0f) != 0x08)
      error("Unknown compression method in flate stream");
    if (((cmf &lt;&lt; 8) + flg) % 31 != 0) error("Bad FCHECK in flate stream");
    if (flg &amp; 0x20) error("FDICT bit set in flate stream");

    this.bytes = bytes;
    this.bytesPos = bytesPos;

    this.codeSize = 0;
    this.codeBuf = 0;

    DecodeStream.call(this);
  }

  constructor.prototype = Object.create(DecodeStream.prototype);

  constructor.prototype.getBits = function(bits) {
    var codeSize = this.codeSize;
    var codeBuf = this.codeBuf;
    var bytes = this.bytes;
    var bytesPos = this.bytesPos;

    var b;
    while (codeSize &lt; bits) {
      if (typeof (b = bytes[bytesPos++]) == "undefined")
        error("Bad encoding in flate stream");
      codeBuf |= b &lt;&lt; codeSize;
      codeSize += 8;
    }
    b = codeBuf &amp; ((1 &lt;&lt; bits) - 1);
    this.codeBuf = codeBuf >> bits;
    this.codeSize = codeSize -= bits;
    this.bytesPos = bytesPos;
    return b;
  };

  constructor.prototype.getCode = function(table) {
    var codes = table[0];
    var maxLen = table[1];
    var codeSize = this.codeSize;
    var codeBuf = this.codeBuf;
    var bytes = this.bytes;
    var bytesPos = this.bytesPos;

    while (codeSize &lt; maxLen) {
      var b;
      if (typeof (b = bytes[bytesPos++]) == "undefined")
        error("Bad encoding in flate stream");
      codeBuf |= b &lt;&lt; codeSize;
      codeSize += 8;
    }
    var code = codes[codeBuf &amp; ((1 &lt;&lt; maxLen) - 1)];
    var codeLen = code >> 16;
    var codeVal = code &amp; 0xffff;
    if (codeSize == 0 || codeSize &lt; codeLen || codeLen == 0)
      error("Bad encoding in flate stream");
    this.codeBuf = codeBuf >> codeLen;
    this.codeSize = codeSize - codeLen;
    this.bytesPos = bytesPos;
    return codeVal;
  };

  constructor.prototype.generateHuffmanTable = function(lengths) {
    var n = lengths.length;

    // find max code length
    var maxLen = 0;
    for (var i = 0; i &lt; n; ++i) {
      if (lengths[i] > maxLen) maxLen = lengths[i];
    }

    // build the table
    var size = 1 &lt;&lt; maxLen;
    var codes = new Uint32Array(size);
    for (
      var len = 1, code = 0, skip = 2;
      len &lt;= maxLen;
      ++len, code &lt;&lt;= 1, skip &lt;&lt;= 1
    ) {
      for (var val = 0; val &lt; n; ++val) {
        if (lengths[val] == len) {
          // bit-reverse the code
          var code2 = 0;
          var t = code;
          for (var i = 0; i &lt; len; ++i) {
            code2 = (code2 &lt;&lt; 1) | (t &amp; 1);
            t >>= 1;
          }

          // fill the table entries
          for (var i = code2; i &lt; size; i += skip) codes[i] = (len &lt;&lt; 16) | val;

          ++code;
        }
      }
    }

    return [codes, maxLen];
  };

  constructor.prototype.readBlock = function() {
    function repeat(stream, array, len, offset, what) {
      var repeat = stream.getBits(len) + offset;
      while (repeat-- > 0) array[i++] = what;
    }

    // read block header
    var hdr = this.getBits(3);
    if (hdr &amp; 1) this.eof = true;
    hdr >>= 1;

    if (hdr == 0) {
      // uncompressed block
      var bytes = this.bytes;
      var bytesPos = this.bytesPos;
      var b;

      if (typeof (b = bytes[bytesPos++]) == "undefined")
        error("Bad block header in flate stream");
      var blockLen = b;
      if (typeof (b = bytes[bytesPos++]) == "undefined")
        error("Bad block header in flate stream");
      blockLen |= b &lt;&lt; 8;
      if (typeof (b = bytes[bytesPos++]) == "undefined")
        error("Bad block header in flate stream");
      var check = b;
      if (typeof (b = bytes[bytesPos++]) == "undefined")
        error("Bad block header in flate stream");
      check |= b &lt;&lt; 8;
      if (check != (~blockLen &amp; 0xffff))
        error("Bad uncompressed block length in flate stream");

      this.codeBuf = 0;
      this.codeSize = 0;

      var bufferLength = this.bufferLength;
      var buffer = this.ensureBuffer(bufferLength + blockLen);
      var end = bufferLength + blockLen;
      this.bufferLength = end;
      for (var n = bufferLength; n &lt; end; ++n) {
        if (typeof (b = bytes[bytesPos++]) == "undefined") {
          this.eof = true;
          break;
        }
        buffer[n] = b;
      }
      this.bytesPos = bytesPos;
      return;
    }

    var litCodeTable;
    var distCodeTable;
    if (hdr == 1) {
      // compressed block, fixed codes
      litCodeTable = fixedLitCodeTab;
      distCodeTable = fixedDistCodeTab;
    } else if (hdr == 2) {
      // compressed block, dynamic codes
      var numLitCodes = this.getBits(5) + 257;
      var numDistCodes = this.getBits(5) + 1;
      var numCodeLenCodes = this.getBits(4) + 4;

      // build the code lengths code table
      var codeLenCodeLengths = Array(codeLenCodeMap.length);
      var i = 0;
      while (i &lt; numCodeLenCodes)
        codeLenCodeLengths[codeLenCodeMap[i++]] = this.getBits(3);
      var codeLenCodeTab = this.generateHuffmanTable(codeLenCodeLengths);

      // build the literal and distance code tables
      var len = 0;
      var i = 0;
      var codes = numLitCodes + numDistCodes;
      var codeLengths = new Array(codes);
      while (i &lt; codes) {
        var code = this.getCode(codeLenCodeTab);
        if (code == 16) {
          repeat(this, codeLengths, 2, 3, len);
        } else if (code == 17) {
          repeat(this, codeLengths, 3, 3, (len = 0));
        } else if (code == 18) {
          repeat(this, codeLengths, 7, 11, (len = 0));
        } else {
          codeLengths[i++] = len = code;
        }
      }

      litCodeTable = this.generateHuffmanTable(
        codeLengths.slice(0, numLitCodes)
      );
      distCodeTable = this.generateHuffmanTable(
        codeLengths.slice(numLitCodes, codes)
      );
    } else {
      error("Unknown block type in flate stream");
    }

    var buffer = this.buffer;
    var limit = buffer ? buffer.length : 0;
    var pos = this.bufferLength;
    while (true) {
      var code1 = this.getCode(litCodeTable);
      if (code1 &lt; 256) {
        if (pos + 1 >= limit) {
          buffer = this.ensureBuffer(pos + 1);
          limit = buffer.length;
        }
        buffer[pos++] = code1;
        continue;
      }
      if (code1 == 256) {
        this.bufferLength = pos;
        return;
      }
      code1 -= 257;
      code1 = lengthDecode[code1];
      var code2 = code1 >> 16;
      if (code2 > 0) code2 = this.getBits(code2);
      var len = (code1 &amp; 0xffff) + code2;
      code1 = this.getCode(distCodeTable);
      code1 = distDecode[code1];
      code2 = code1 >> 16;
      if (code2 > 0) code2 = this.getBits(code2);
      var dist = (code1 &amp; 0xffff) + code2;
      if (pos + len >= limit) {
        buffer = this.ensureBuffer(pos + len);
        limit = buffer.length;
      }
      for (var k = 0; k &lt; len; ++k, ++pos) buffer[pos] = buffer[pos - dist];
    }
  };

  return constructor;
})());

export { DecodeStream, FlateStream };
</code></pre>
        </article>
    </section>




    
    
</div>

<br class="clear">

<footer>
    Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.6.4</a> on Mon Dec 07 2020 15:13:07 GMT+0100 (Central European Standard Time) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
</footer>

<script>prettyPrint();</script>
<script src="scripts/polyfill.js"></script>
<script src="scripts/linenumber.js"></script>



</body>
</html>
